<template>
  <div>
    <el-container class="home_container">
      <el-header class="home_header">
        <div style="height:100%">
          <img src="../assets/logo2.png" alt height="100%" />
          <span>利物浦官方商城后台管理系统</span>
        </div>
        <el-button type="danger" round @click="logout()">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px':'200px'" class="home_aside">
          <i class="toggle" :class="isCollapse ? 'el-icon-s-unfold':'el-icon-s-fold'" @click="toggle()"></i>
          <el-menu
            :collapse-transition="false"
            :collapse="isCollapse"
            unique-opened
            background-color="#c54b49"
            text-color="#fff"
            active-text-color="#ffd04b"
            v-if="menus.length > 0" router
          >
            <el-submenu :index="menu.order + ''" v-for="menu in menus" :key="menu.id">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{menu.authName}}</span>
              </template>
              <el-menu-item
                :index="'/' + menu.path"
                v-for="m in menu.children"
                :key="m.id"
              >
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{m.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main class="home_main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  created: function() {
    this.getMenus();
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getMenus() {
      const { data: res } = await this.$http.get("/menus");
      if (res.meta.status != 200) return this.$message.error(res.meta.msg);
      this.menus = res.data;
    },
    toggle(){
      this.isCollapse = !this.isCollapse;
    }
  },
  data() {
    return {
      menus: [],
      isCollapse: false
    };
  }
};
</script>

<style lang="less" scoped>
.home_header {
  background-color: #c40200;
  display: flex;
  justify-content: space-between;
  font-size: 20px;
  align-items: center;
  color: white;
  > div {
    display: flex;
    align-items: center;
  }
}

.home_aside {
  background-color: #c54b49;
  .el-menu {
    border-right: none !important;
  }
  .toggle {
    color: white;
    background-color: #e04040;
    display: flex;
    justify-content: center;
    cursor: pointer;
    height: 25px;
    align-items:center;
  }
}

.home_container {
  height: 100vh;
}

.el-main{
  background-color: #f2f2f2;
}
</style>